#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

if command -v wine >/dev/null ;then
  env WINEPREFIX="$HOME/.wine" wine C:\\windows\\command\\start.exe /Unix ~/.wine/dosdevices/c:/ProgramData/Microsoft/Windows/Start\ Menu/Programs/LEGO\ Company/Uninstall\ LEGO\ Digital\ Designer.lnk || error "Wine uninstallation command failed!"
else
  echo "WARNING: 'wine' command not found! Not uninstalling Lego Digital Designer."
fi

#wait until finished
while ps aux | grep -v grep | grep wine | grep -q 'LEGO Digital Designer' ;do
  sleep 1
done

rm -rf ~/'.local/share/applications/wine/Programs/LEGO Company'
